<template>
  <div class="addMenuCls">
    <el-card>
      <el-form
        label-position="right"
        label-width="80px"
        :model="formData">
        <el-form-item label="菜单名称：">
          <el-input v-model="formData.name"></el-input>
        </el-form-item>
        <el-form-item label="菜单路径：">
          <el-input v-model="formData.href"></el-input>
        </el-form-item>
        <el-form-item label="上级菜单：">
          <el-select v-model="formData.parentId" clearable placeholder="请选择上级菜单">
            <el-option
              v-for="item in parentList"
              :key="item.value"
              :label="item.label"
              :value="item.value">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="描述：">
          <el-input v-model="formData.description"></el-input>
        </el-form-item>
        <el-form-item label="前端图标：">
          <el-input v-model="formData.icon"></el-input>
        </el-form-item>
        <el-form-item label="是否显示：">
         <template>
          <el-radio v-model="formData.shown" :label="true">是</el-radio>
          <el-radio v-model="formData.shown" :label="false">否</el-radio>
        </template>
        </el-form-item>
        <el-form-item label="排序：">
          <el-input v-model="formData.orderNum"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button
            type="primary"
            @click="onSubmit">提交</el-button>
          <el-button>重置</el-button>
        </el-form-item>
      </el-form>
    </el-card>
  </div>
</template>
<script lang="ts">
import { getEditMenuInfo, saveOrUpdate } from '@/api/menu'
import Vue from 'vue'
export default Vue.extend({
  name: 'AddMenu',
  data () {
    return {
      formData: {
        name: '',
        href: '',
        parentId: -1,
        description: '',
        icon: '',
        shown: true,
        orderNum: 0
      },
      parentList: []
    }
  },
  methods: {
    async onSubmit () {
      const data = await saveOrUpdate(this.formData)
      if (data) {
        this.$message.success('提交成功成功')
        this.$router.push({ name: 'menu' })
      }
    },
    async getAddMenuInfo () {
      const data = await getEditMenuInfo()
      console.log(data)
      this.parentList = data.parentMenuList
    }
  },
  created () {
    this.getAddMenuInfo()
  }
})
</script>
<style scoped lang="scss">
.el-input{
  width: 1000px;
}
::v-deep .el-form-item__label{
  width:120px !important;
}
</style>
